﻿using System;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using AIniciacao.Lib.Screens;
using AIniciacao.Lib.Input;
using AIniciacao.Lib;
using System.Collections.Generic;
using Module_Persistence;
using Module_Basic_Entities;
using AIniciacao;
using AIniciacao.Lib.GameUtils;
using AIniciacao.Lib.Sprites;
using AIniciacao.Lib.Audio;
namespace AIniciacao.Lib.Characters
{
    public class Stanley:Personagem
    {
        public Stanley(Texture2D imgPerfil, Texture2D imgLeft, Texture2D imgRight, Texture2D imgUp, Texture2D imgDown, Vector2 posDet, Vector2 velDet, PersonagemAnimation personagemAnimations)
        :base(imgPerfil,imgLeft,imgRight,imgUp,imgDown,posDet,velDet,personagemAnimations){
            this.imgPerfil = imgPerfil;
            this.imgLeft = imgLeft;
            this.imgRight = imgRight;
            this.imgUp = imgUp;
            this.imgDown = imgDown;
            this.posDet = posDet;
            this.velDet = velDet;
            this.personagemAnimations = personagemAnimations;

        }
        public override void HandleInput(InputState input, PlayerIndex? ControllingPlayer, List<string> footStepSounds)
        {
            int playerIndex = (int)ControllingPlayer;
            PersonagemAnimations.lastAnimation = personagemAnimations.currentAnimation;

            if (input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Up) || input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Down)
                 || input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Left) || input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Right))
            {

                if (currentSoundIndex >= footStepSounds.Count)
                    currentSoundIndex = 0;
                if (AudioFactory.audioManager.getPlayingSoundsCount() <= 1 || firstFootStep)
                {
                    AudioFactory.audioManager.PlaySound(footStepSounds[currentSoundIndex++]);
                    firstFootStep = false;
                }


                if (input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Up))
                {
                    posDet.Y -= VelDet.Y;
                    PersonagemAnimations.changeAnimation("correc");
                }
                else if (input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Down))
                {
                    posDet.Y += VelDet.Y;
                    PersonagemAnimations.changeAnimation("correb");
                }

                else if (input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Left))
                {
                    posDet.X -= VelDet.X;
                    PersonagemAnimations.changeAnimation("corree");
                }

                else if (input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Right))
                {
                    posDet.X += VelDet.X;
                    PersonagemAnimations.changeAnimation("corred");
                }
            }
            else
            {
                PersonagemAnimations.changeAnimation("fica");
                currentSoundIndex = 0;
            }

        }
        public override void LastMovement()
        {
            switch (personagemAnimations.currentAnimation)
            {
                case "corred":
                    posDet.X -=  VelDet.X;
                    break;
                case "corree":
                    posDet.X += VelDet.X;
                    break;
                case "correc":
                    posDet.Y += VelDet.Y;
                    break;
                case "correb":
                    posDet.Y -= VelDet.Y;
                    break;

            }
        }
        
  
    }
}
